package handlers

import (
	"github.com/gin-gonic/gin"
	"img-text-hub/models"
	"net/http"
)

func Add(c *gin.Context) {
	name := c.PostForm("name")
	price := c.PostForm("price")
	book := models.Book{
		Name:  name,
		Price: price,
	}
	err := models.DB.Create(&book).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "发布失败",
		})
		return
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "发布成功",
		})
		return
	}
}
func List(c *gin.Context) {
	var book models.Book
	err := models.DB.Find(&book).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "查询失败",
		})
		return
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "查询成功",
		})
		return
	}
}

func Login(c *gin.Context) {

}